const path = require('path');
const HtmlPlugin = require('html-webpack-plugin');

const htmlPlugin = new HtmlPlugin({ template: './src/index.html', filename: 'index.html' }, { template: './src/favicon.ico', filename: 'favicon.ico' })

module.exports = {
    mode: 'development', // 当前是开发模式
    // mode: 'production', // 当前是生产模式
    entry: path.join(__dirname, './src/index.js'),
    output: {
        path: path.join(__dirname, './dist'),
        filename: 'main.js'
    },
    plugins: [htmlPlugin],
    // 自动打开浏览器
    // devServer: {
    //     open: true,
    //     port: 9000,
    //     host: '127.0.0.1'
    // },
    module: {
        rules: [
            // 定义了不同模块对应的css loader
            { test: /\.css/, use: ['style-loader', 'css-loader'] },
            { test: /\.less/, use: ['style-loader', 'css-loader', 'less-loader'] },
            { test: /\.jpg|png|git$/, use: 'url-loader?limit=22229' },
            // 过滤第三方包
            { test: /\.js$/, use: 'babel-loader', exclude: /node_modules/ }
        ]
    }
}